<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

    <title>$!app_name</title>
     
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="${base}/include/css/msg.css" rel="stylesheet" type="text/css"/>

    <link href="${base}/include/css/default.css" rel="stylesheet" type="text/css"/>
	<script type='text/javascript'>
		var CONTEXTPATH = '${base}';
	</script>
    <script src="${base}/include/js/main.js"></script>
    <script src="${base}/include/js/string.js"></script>
   	<!-- 分页  注意顺序 -->
	<link href="${base}/include/css/themes/gray/easyui.css" rel="stylesheet" type="text/css"/> 	
	<script src="${base}/include/js/jquery.easyui.min.js"></script>	
    <script type="text/javascript"
	src="${base}/include/controls/ztree/jquery.ztree.core-3.5.min.js"></script> 
	<link rel="stylesheet" href="${base}/include/controls/ztree/zTreeStyle/zTreeStyle.css" type="text/css">

    <SCRIPT type="text/javascript">
           <!--
           var ztree;
           function initTree(){
				var setting = {
                        async: {
                            enable: true,
                            url:"${base}/private/sys/dict/treelist",
                            autoParam:["id"]
                        },
                        view:{
                             nameIsHTML: true
                        },
                        callback: {
                            onAsyncSuccess: zTreeOnAsyncSuccess
                        }
                 }; 
        	    ztree=jQuery.fn.zTree.init(jQuery("#treeDemo"), setting);
			}
           function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
               var tid=$("#treeid").val();
               ztree.selectNode(ztree.getNodeByParam("id",tid , null));
               if(tid!=""){
                   for(var i=4;i<=tid.length;i=i+4){
                        ztree.expandNode(ztree.getNodeByParam("id", tid.substring(0,i), null), true);
                   }
               }
           }
           function del(){
       	    var ids = [];
       		var arr = $('#dg1').datagrid('getSelections');
       	    if (!arr || arr.length == 0) {
       	        Dialog.alert("请先选择要删除的内容！");
       	        return;
       	    }
       	    for(var i=0; i<arr.length; i++){
       	        ids.push(arr[i].id);
       	    }
       	    Dialog.confirm("确定删除？", function(){
       	    	jQuery.ajax({
       	    	 	type: 'POST',
       	    		url : "${base}/private/sys/dict/deleteIds" ,
       	    		data : {"ids":ids.toString()},
       	    		success : function (res) { 
       	    			if(res=="true"){    				
       	    				Dialog.alert("删除成功！");
       	    				initTree();
                            loadGrid();
       	    			}else{
       	    				Dialog.alert("删除失败！");
       	    			}			 
       	    			return false;
       	    		},
       	    		fail : function(res) {
       	    			Dialog.alert("系统错误!");
       	    		}
       	    	});
       	    }, "", 250, 100);    
       	}
		   function addDict()
           {
	        	var d = new Dialog("Add");
	           	d.Width = 380;
	           	d.Height = 240;
	           	d.Title = "添加";
	           	d.URL = "${base}/private/sys/dict/toadd?id="+$("#treeid").val();
	           	d.onLoad = function(){
                    $DW.$("#dkey").focus();
	           	};
	           	d.OKEvent = function(){
	           		if($DW.Verify.hasError()){
	          		  return;
	          	     }
	           		addSave();
	           	}; 
	           	d.show();
           }
           function getDict(tag){
               jQuery.ajax({
                   type: 'POST',
                   url : "${base}/private/sys/dict/getdict" ,
                   data : {"ids":$("#treeid").val(),"tag":tag},
                   success : function (res) {
                       if(res=="true"){
                           $D.close();
                           Dialog.alert("导入成功！");
                           initTree();
                           loadGrid();
                       }else{
                           Dialog.alert("导入失败！");
                       }
                       return false;
                   },
                   fail : function(res) {
                       Dialog.alert("系统错误?!");
                   }
               });
           }
		   function addSave(){
	       		jQuery.ajax({
	       			 	type: 'POST',
	           			url : "${base}/private/sys/dict/add" ,
	           			data : $DW.$("#form1").serialize(),
	           			success : function (res) { 
	           				if(res=="true"){
	           					$D.close();
	           					Dialog.alert("添加成功！");
	           					initTree();
	           					loadGrid();
	           				}else{
	           					Dialog.alert("添加失败！");
	           				}
	           				return false;
	           			},
	           			fail : function(res) {
	           				Dialog.alert("系统错误?!");
	           			}
	               });
       	   }
		   function update(id)
           {
               if(id==""){
                   var arr = $('#dg1').datagrid('getSelections');
                   if (arr && arr.length > 0) {
                       id=arr[0].id;
                   }
               }
               if(id==""){
                   Dialog.alert("请选择修改项");
                   return;
               }
	        	var d = new Dialog("Update");
	           	d.Width = 380;
	           	d.Height = 240;
	           	d.Title = "修改";
	           	d.URL = "${base}/private/sys/dict/toupdate?id="+id;
	           	d.onLoad = function(){

	           	}
	           	d.OKEvent = function(){
	           		if($DW.Verify.hasError()){
	          		  return;
	          	     }
	           		updateSave();
	           	};
	           	d.show();
           }
		   function updateSave(){
	       		jQuery.ajax({
	       			 	type: 'POST',
	           			url : "${base}/private/sys/dict/update" ,
	           			data : $DW.$("#form1").serialize(),
	           			success : function (res) { 
	           				if(res=="true"){
	           					$D.close();
	           					Dialog.alert("修改成功！");
	           					initTree();
	           					loadGrid();
	           				}else{
	           					Dialog.alert("修改失败！");
	           				}
	           				return false;
	           			},
	           			fail : function(res) {
	           				Dialog.alert("系统错误?!");
	           			}
	               });
       	   }
           function sort()
           {

               var d = new Dialog("Sort");
               d.Width = 450;
               d.Height = 370;
               d.Title = "栏目排序";
               d.URL = "/private/sys/dict/toSort?id="+$("#treeid").val();
               d.OKEvent = function() {
               	 $DW.getIdsTree();
               	 sortUpdate();
                    
               };
               d.show();
           }
           function sortUpdate(){
           	   if($DW.Verify.hasError()){
           		  return;
           	     }
                $DW.Page.MinMessage.Show({
                    text: '正在执行',
                    type: 'load'
                });
           		 jQuery.ajax({
           				type: 'POST',
               			url : "/private/sys/dict/sort" ,
               			data : $DW.$("#form1").serialize(),
               			success : function (res) { 
               				$DW.Page.MinMessage.Hide();
               				if(res=="true"){
               					$D.close();
               					Dialog.alert("排序成功！");
               					initTree();
               					loadGrid();

               				}else{
               					Dialog.alert("排序失败！");
               				}
               				
               				return false;
               			},
               			fail : function(res) {
               				Dialog.alert("系统错误?!");
               			}
               		});
           	 
           }

           function getWidth(percent){
        	   return document.body.clientWidth*percent;
		   }
           function list(id){
               $("#treeid").val(id);
               loadGrid();
           }
           function loadGrid(){
        	   $("#dg1").datagrid({
        	        width:"auto",
        	   		height:"auto",
        	        nowrap: false,  
        	        striped: false,  
        	        border: true,  
        	        collapsible:false,//是否可折叠的  
        	        fit: true,//自动大小  
        	        url:"${base}/private/sys/dict/list",
        	        //sortName: 'code',  
        	        //sortOrder: 'desc', 
        	        queryParams:{"treeid":Page.getValue("treeid")},
        	        remoteSort:false,   
        	        idField:"id",
        	        singleSelect:false,//是否单选
                    pagination:true,//分页控件
                    rownumbers:true,//行号
                    fitColumns: true,//行自适应
                    pageSize: 10,
                    pageList:[5,10,15,20,30,40,50],
                    loadMsg:'数据加载中...',
                    onDblClickRow:function(rowIndex,row)
                    {
                        update(row.id);
                    },
        	        columns:[[
                        {title : 'ID',field : 'name',width:getWidth(0.20),align : 'left',
                            formatter:function(value,rec,index){
                                return rec.id;
                            }
                        },
						{title : 'KEY',field : 'dkey',width:getWidth(0.25),align : 'center'},
                        {title : 'VALUE', field: 'dval',width:getWidth(0.25),align : 'center'
                        },
                        {title : '状态',field : 'status',align : 'left',
                            formatter:function(value,rec,index){
                                if(rec.status==1)
                                {
                                    return '<span style="color:#FF0000">禁用</span>';
                                }
                                else
                                {
                                    return '启用';
                                }
                            }},
                        {title : '说明', field: 'txt',width:getWidth(0.30),align : 'center'
                        }
        	        ]],frozenColumns:[[
        	          	            {field:"id",checkbox:true}
        	          	        	 ]]
        	    });
               //设置分页控件
               var p = $("#dg1").datagrid("getPager");
               $(p).pagination({
                   beforePageText: "第",//页数文本框前显示的汉字
                   afterPageText: "页    共 {pages} 页",
                   displayMsg: "当前显示 {from} - {to} 条记录   共 {total} 条记录"
               });
           }
           function initBtn(){
        	   Page.initBtn();
        	   $!initBtn
           }
           Page.onLoad(function(){
				initBtn();
        	    initTree();
        	    loadGrid();
           }); 
           $(window).resize(function () {
          		clearTimeout(timer);
          		timer=setTimeout(function(){
          		  $('#dg1').treegrid('resize');
          		  $('div.panel-body').css('width','auto'); 
          		 },200);
          		});
           //-->
       </SCRIPT>
</head>
<body leftmargin="0" topmargin="0" style="overflow-x: hidden; overflow-y: auto">
<form name="form1" id="form1" >
    <input type="hidden" name="treeid" id="treeid" value="">

	<table width="100%" border="0" cellspacing="6" cellpadding="0"
		style="border-collapse: separate; border-spacing: 6px;">
		<tr valign="top">
			<td width="180">
			    <table width="100%" height="100%" border="0" cellspacing="0"
					cellpadding="6" class="blockTable">
					<tr>
						<td style="padding: 6px;" class="blockTdn">
							<div ztype='_Tree'
								style='-moz-user-select: none; height: 390px; width: 200px;'
								id='tree1' class='treeItemN'>
								

								<ul id="treeDemo" class="ztree"></ul>
							</div>

						</td>
					</tr>
					
					
				</table>
			</td>
			<td width="100%" valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="0"
					style="border-collapse: separate; border-spacing: 0px;">
					<tr valign="top">
						<td>
							<table width="100%" border="0" cellpadding="0" cellspacing="0"
								class="blockTable">
								<tr>
									<td class="blockTd">
										<table width="100%" border="0" cellspacing="0" cellpadding="6">
											<tr>
												<td valign="middle"><img
													src="${base}/images/icons/icon042a1.gif"
													width="20" height="20" />&nbsp;字典列表
                                                </td>
											</tr>
											<tr>
												<td style="padding: 0 8px 4px;" id="btnlist">
                                                    <a
                                                            href='javascript:void(0);' ztype='zPushBtn'
                                                            class='zPushBtn' hidefocus='true' tabindex='-1'
                                                            onselectstart='return false' id='BtnAdd' onClick="addDict();"><img
                                                            src="${base}/images/icons/icon022a2.gif"
                                                            width="20" height="20" /><b>添加&nbsp;</b></a> <a
                                                        href='javascript:void(0);' ztype='zPushBtn'
                                                        class='zPushBtn' hidefocus='true' tabindex='-1'
                                                        onselectstart='return false' id='BtnUpdate'
                                                        onClick="update('');"><img
                                                        src="${base}/images/icons/icon022a4.gif"
                                                        width="20" height="20" /><b>修改&nbsp;</b></a> <a
                                                        href='javascript:void(0);' ztype='zPushBtn'
                                                        class='zPushBtn' hidefocus='true' tabindex='-1'
                                                        onselectstart='return false' id='BtnDel' onClick="del();"><img
                                                        src="${base}/images/icons/icon022a3.gif"
                                                        width="20" height="20" /><b>删除&nbsp;</b></a> <a
													href='javascript:void(0);' ztype='zPushBtn'
													class='zPushBtn' hidefocus='true' tabindex='-1'
													onselectstart='return false' id='BtnPaixu' onClick="sort();"><img
														src="${base}/images/icons/icon400a13.gif"
														width="20" height="20" /><b>排序&nbsp;</b></a> 
												</td>
												<td algin="right" width="85">
												  

												 </td>
												  
											</tr> 
											<tr>
												 <td style="padding:0px 5px;"height="350" colspan="3">                                             
                                            <table width="100%" height="100%" id="dg1" size="10" cellpadding="2" cellspacing="0">
												<tr><td></td></tr>
											</table>                                          
                                            </td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>




			</td>
		</tr>
	</table>
	</form>
</body>
</html>